package com.hbwxz.thread;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * Java 就是一个天生的多线程
 *
 * @author shenzw
 * @date 2024/1/29
 */
public class JavaThread {

    public static void main(String[] args) {

        // 线程管理 bean
        ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
        ThreadInfo[] threadInfos = threadMxBean.dumpAllThreads(true, true);

        // 遍历线程信息
        for (ThreadInfo threadInfo : threadInfos) {
            /*
                [5] Monitor Ctrl-Break
                [4] Signal Dispatcher
                [3] Finalizer
                [2] Reference Handler
                [1] main
             */
            System.out.println("[" + threadInfo.getThreadId() + "]\t" + threadInfo.getThreadName());
        }
    }
}
